// https://next.router.vuejs.org/zh/guide/advanced/dynamic-routing.html
import {
	createRouter,
	createWebHashHistory,
	createWebHistory
} from 'vue-router';
// import * as VueRouter  from 'vue-router';

import Layout from "/@/layout/index.vue";

export const constantRoutes = [{
		path: '/redirect',
		component: Layout,
		hidden: true,
		name: 'Redirect',
		children: [{
			path: '/redirect/:path(.*)',
			name: 'RedirectC',
			component: () => import('/@/views/redirect/index.vue')
		}]
	},
	{
		path: "/login",
		name: "Login",
		hidden: true,
		component: () => import("/@/views/login/index.vue"),
		meta: {
			title: '登录',
			icon: "el-icon-s-home",
			noCache: true,
			roles: ['admin'],
		},
	},
	{
		path: '/401',
		component: () => import('/@/views/error-page/401.vue'),
		hidden: true,
	},
	// {
	// 	path: "/",
	// 	name: "Dashboard",
	// 	component: Layout,
	// 	redirect: "/dashboard",
	// 	children: [{
	// 		path: "/",
	// 		name: "Dashboard",
	// 		component: () => import("/@/views/dashboard/index.vue"),
	// 		meta: {
	// 			title: '工作台',
	// 			icon: "dashboard",
	// 			noCache: true,
	// 			roles: ['admin'],
	// 		},
	// 	}, ],
	// },
	{
		path: "/",
		name: "Version",
		component: Layout,
		redirect: "/version",
		children: [{
			path: "/",
			name: "Version",
			component: () => import("/@/views/version/list.vue"),
			meta: {
				title: '产线',
				icon: "dashboard",
				noCache: true,
				roles: ['admin'],
			},
		}],
	}
]
export const asyncRoutes = [





	// { path : '*', redirect : '/404', hidden : true }

]

const createRouters = createRouter({
	// "history": createWebHistory()
	// "hash": createWebHashHistory()
	// "abstract": createMemoryHistory()
	history: createWebHashHistory('/'), // base 当成参数传递了
	routes: constantRoutes.concat(asyncRoutes),
	scrollBehavior: () => ({
		left: 0,
		top: 0
	}), //  return 期望滚动到哪个的位置
})

//
const router = createRouters

export function resetRouter() {
	const WHITE_NAME_LIST = [
		'Login'
	]
	router.getRoutes().forEach((route) => {
		const {
			name
		} = route;
		if (name && !WHITE_NAME_LIST.includes(name)) {
			router.hasRoute(name) && router.removeRoute(name);
		}
	});
}

export default router
